home *** CD-ROM | disk | FTP | other *** search
/ Chip: Special XP & Vista / Chip Spesial XP & Vista.iso / 3_Gadgets / gdAmp / gdamp.gg / main.js < prev    next >
Text File  |  2007-08-14  |  7KB  |  368 lines

  1. ∩╗┐/* gdAmp - Copyright (c) Aug 2007 Krzysztof Olczyk */
  2. var dtbLbl = null;
  3. var winamp = null;
  4. var ps = 0;
  5. var dur = 0;
  6. var pos = 0;
  7. var songind = 0;
  8. var songtitle = "";
  9. var remtime = false;
  10. var showst = true;
  11.  
  12. function formattime(tm)
  13. {
  14.     return Math.floor(tm / 60) + ':' + ((tm % 60) < 10 ? '0' : '') + (tm % 60)    
  15. }
  16.  
  17. function formattitle()
  18. {
  19.     return (songind + 1) + ". " + songtitle + " (" + formattime(dur) + ")";
  20. }
  21.  
  22. var upd_timeout = 500;
  23. var pir = false;
  24. function updateview()
  25. {
  26.     songind = winamp.PlaylistIndex;
  27.     songtitle = winamp.GetTitleAt(songind);
  28.  
  29.     if (winamp.PlayingStatus != ps && winamp.PlayingStatus == 1)
  30.     {
  31.         popupNewTrack();
  32.     }
  33.  
  34.     ps = winamp.PlayingStatus;
  35.     dur = winamp.Duration;
  36.     pos = winamp.Position;
  37.     sb.value = winamp.Volume;
  38.  
  39.     var newtitl;
  40.  
  41.     if (winamp.isRunning)
  42.         newtitl = formattitle();
  43.     else
  44.         newtitl = NOTRUNNING;
  45.     
  46.     
  47.     if (dtbLbl.innerText != newtitl)
  48.     {
  49.         dtbLbl.innerText = newtitl;
  50.         resetAnimTitle();
  51.         animateTitle();
  52.  
  53.         if (winamp.isRunning && ps == 1)
  54.             popupNewTrack();
  55.     }
  56.  
  57.     btn1.src = (ps == 1 ? 'images\\media-playback-pause.png' : 'images\\media-playback-start.png');
  58.     btn1.tooltip = (ps == 1 ? PAUSE : PLAY);
  59.  
  60.     if (!winamp.isRunning)
  61.         {
  62.         pbPosition.max = 0;
  63.         pbPosition.enabled = true;
  64.  
  65.         setTimeout("updateview()", upd_timeout);
  66.  
  67.         if (!pir)
  68.         {
  69.             pir = true;
  70.             popupWinampClosed();
  71.         }
  72.  
  73.         return;    
  74.     }    
  75.  
  76.     pir = false;
  77.     
  78.     if (showst)
  79.     {
  80.         switch (ps)
  81.         {
  82.             case 0:
  83.                 lblStatus.innerText = STOPPED;
  84.                 break;
  85.             case 1:
  86.                 lblStatus.innerText = PLAYING;
  87.                 break;
  88.             case 3:
  89.                 lblStatus.innerText = PAUSED;
  90.                 break;
  91.         }
  92.     }
  93.     else
  94.         lblStatus.innerText = "";
  95.  
  96.     if (ps != 0) // if not stopped
  97.     {
  98.         pbPosition.max = dur;
  99.         pbPosition.enabled = true;
  100.         pbPosition.value = pos;
  101.         if (remtime)
  102.             lblTime.innerText = "-" + formattime(dur - pos - 1);
  103.         else
  104.             lblTime.innerText = formattime(pos);
  105.     }
  106.     else
  107.     {
  108.         pbPosition.enabled = false;
  109.         pbPosition.max = 0;
  110.         lblTime.innerText = '0:00';
  111.     }
  112.  
  113.     setTimeout("updateview()", upd_timeout);
  114. }
  115.  
  116. function view_onOpen() 
  117. {
  118.     try
  119.     {
  120.         winamp = new ActiveXObject("Winamp.Controller");
  121.     }
  122.     catch (e)
  123.     {
  124.         InstallPlugin();
  125.     }
  126.     
  127.     options.putDefaultValue("show_remaining", "false");
  128.     remtime = options.getValue("show_remaining") == "true";
  129.  
  130.     options.putDefaultValue("show_status", "true");
  131.     showst = options.getValue("show_status") == "true";
  132.  
  133.  
  134.     dtbLbl = dTitleBar.AppendElement("<label y='3' color='#ff0000' size='9' font='verdana'>" + GADGET_NAME + "</label>");
  135.     dtbLbl.tooltip = dTitleBar.tooltip;
  136.     updateview();
  137.     applycolors();
  138. }
  139.  
  140. function bmo(i)
  141. {
  142.    eval("btn" + i).opacity = 150;
  143. }
  144.  
  145. function bml(i)
  146. {
  147.    eval("btn" + i).opacity = 255;
  148. }
  149.  
  150. function checkwinamp()
  151. {
  152.     if (!winamp.isRunning)
  153.     {
  154.         if (confirm(WANNARUN))
  155.             winamp.Execute();
  156.     }
  157. }
  158.  
  159. function doplay()
  160. {
  161.     checkwinamp();
  162.     if (winamp.PlayingStatus == 0)
  163.         winamp.play();
  164.     else if (winamp.PlayingStatus == 3)
  165.         winamp.pause();
  166.     else
  167.         winamp.pause();
  168. }
  169.  
  170. function dostop()
  171. {
  172.     checkwinamp();
  173.     winamp.stop();
  174. }
  175.  
  176. function posclick()
  177. {
  178.     checkwinamp();
  179.     winamp.position = pbPosition.value;
  180. }
  181.  
  182. function doopen()
  183. {
  184.     checkwinamp();
  185.     winamp.BringToFront();
  186.     winamp.PopupLoadFile();
  187. }
  188.  
  189. function doprev()
  190. {
  191.     checkwinamp();
  192.     winamp.Prev();
  193. }
  194.  
  195. function donext()
  196. {
  197.     checkwinamp();
  198.     winamp.Next();
  199. }
  200.  
  201. function sb_onchange()
  202. {
  203.     winamp.Volume = sb.value;
  204. }
  205.  
  206. function toggle_rem()
  207. {
  208.     remtime = !remtime;
  209.     options.putValue("show_remaining", remtime ? "true" : "false");
  210. }
  211.  
  212. function toggle_sst()
  213. {
  214.     showst = !showst;
  215.     options.putValue("show_status", showst ? "true" : "false");
  216. }
  217.  
  218. function toggle_visible() 
  219.     winamp.visible = !winamp.visible; 
  220.     if (!winamp.visible)
  221.     {
  222.         popupWinampHidden();
  223.     }
  224. }
  225.  
  226. function Colors()
  227. {
  228.     this.title = "#ff0000";
  229.     this.time = "#000000";
  230.     this.status = "#000000";
  231.     this.customcolors = "";
  232. }
  233.  
  234. Colors.prototype.Save = function()
  235. {
  236.     options.putValue("color1", this.title);
  237.     options.putValue("color2", this.time);
  238.     options.putValue("color3", this.status);
  239.     options.putValue("colorc", this.customcolors);
  240. }
  241.  
  242. Colors.prototype.Load = function()
  243. {
  244.     if (options.exists("color1"))
  245.         this.title =  options.getValue("color1");
  246.     if (options.exists("color2"))
  247.         this.time =  options.getValue("color2");
  248.     if (options.exists("color3"))
  249.         this.status =  options.getValue("color3");
  250.     if (options.exists("colorc"))
  251.         this.customcolors =  options.getValue("colorc");
  252. }
  253.  
  254. function applycolors()
  255. {
  256.     var colors = new Colors();
  257.     colors.Load();
  258.     dtbLbl.color = colors.title;
  259.     lblTime.color = colors.time;
  260.     lblStatus.color = colors.status;
  261. }
  262.  
  263. function selcolor(wh)
  264. {
  265.     var colors = new Colors();
  266.     colors.Load();
  267.  
  268.     var acs = new ActiveColorSelector();
  269.     
  270.     acs.CustomColorsStr = colors.customcolors;
  271.     acs.ColorStr = eval("colors." + wh);
  272.  
  273.     if (acs.Show(0))
  274.     {
  275.         eval("colors." + wh + " = acs.ColorStr;");
  276.     }
  277.  
  278.     colors.customcolors = acs.CustomColorsStr;
  279.     colors.Save();
  280.     applycolors();
  281.     acs = null;
  282. }
  283.  
  284. function pluginHelper.onAddCustomMenuItems(menu) 
  285. {
  286.     if (winamp.isRunning)
  287.     {
  288.         menu.AddItem(SHUFFLE, winamp.Shuffle ? gddMenuItemFlagChecked : 0, function () { winamp.Shuffle = !winamp.Shuffle; });
  289.         menu.AddItem(REPEAT, winamp.RepeatEnabled ? gddMenuItemFlagChecked : 0, function () { winamp.RepeatEnabled = !winamp.RepeatEnabled; });
  290.         var submenu = menu.AddPopup(PLAYBACK);
  291.         submenu.AddItem(PREV, 0, doprev);
  292.         submenu.AddItem(ps == 1 ? PAUSE : PLAY, 0, doplay);
  293.         submenu.AddItem(STOP, 0, dostop);
  294.         submenu.AddItem(NEXT, 0, donext);
  295.         submenu.AddItem(OPEN, 0, doopen);
  296.         menu.AddItem('', 0x800 /* MF_SEPARATOR */, null);
  297.         menu.AddItem(SHOWREM, remtime ? gddMenuItemFlagChecked : 0, toggle_rem);
  298.         menu.AddItem(SHOWSTAT, showst ? gddMenuItemFlagChecked : 0, toggle_sst);
  299.         menu.AddItem(WINAMP_HIDDEN, winamp.visible ? 0 : gddMenuItemFlagChecked, toggle_visible);
  300.         menu.AddItem('', 0x800 /* MF_SEPARATOR */, null);
  301.         var submenu2 = menu.AddPopup(CONFCOLORS);
  302.         submenu2.AddItem(CTITL, 0, function () { selcolor("title"); });
  303.         submenu2.AddItem(CTIME, 0, function () { selcolor("time"); });
  304.         if (showst)
  305.             submenu2.AddItem(CSTATUS, 0, function () { selcolor("status"); });        
  306.         menu.AddItem(VISITWP, 0, function () { (new ActiveXObject("WScript.Shell")).Run("http://olczyk.krzysztof.googlepages.com"); });
  307.     }
  308.     else
  309.     {
  310.         menu.AddItem(RUNWINAMP, 0, function () { winamp.Execute(); });
  311.     }
  312. }
  313.  
  314. function InstallPlugin()
  315. {
  316.     var ws = new ActiveXObject("WScript.Shell");
  317.     var sh = new ActiveXObject("Shell.Application");
  318.     var wp;
  319.     try
  320.     {
  321.         wp = ws.RegRead("HKCU\\Software\\Winamp\\");    
  322.     }
  323.     catch (e)
  324.     {
  325.         alert(NOWINAMP);
  326.         Plugin.RemoveMe(true);
  327.         return;
  328.     }
  329.     
  330.     alert(INSTALLMSG);
  331.  
  332.     var destobj = sh.NameSpace(wp + "\\Plugins");
  333.     if (destobj == null)
  334.     {
  335.         alert(ERRORINSTALLING);
  336.         Plugin.RemoveMe(true);
  337.         return;
  338.     }
  339.  
  340.     var ef = storage.extract("gen_Winamp.dll");
  341.  
  342.     destobj.CopyHere(ef, 20);
  343.     framework.system.filesystem.DeleteFile(ef);
  344.  
  345.     debug.trace(wp + "\\winamp.exe");
  346.     ws.Run("\"" + wp + "\\winamp.exe\"");
  347.  
  348.     alert(INSTALLMSG2);
  349.  
  350.     try
  351.     {
  352.         winamp = new ActiveXObject("Winamp.Controller");
  353.     }
  354.     catch (e)
  355.     {
  356.         alert(RRORINSTALLING);
  357.         Plugin.RemoveMe(true);
  358.         return;
  359.     }
  360.  
  361. //    view_onOpen();
  362. }
  363.  
  364. function view_onClose()
  365. {
  366.     winamp.visible = true;
  367. }